package cn.mxz.controller;

import cn.mxz.pojo.ResultData;
import cn.mxz.pojo.UserAddr;
import cn.mxz.service.AddrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 小毛
 * @Date 2021/12/2 15:38
 * @Remark 佛祖保佑永无bug~
 */
@RestController
@RequestMapping("addr")
@CrossOrigin
public class AddrController {
    @Autowired
    private AddrService addrService;

    //根据用户id查询地址信息
    @GetMapping("{userId}")
    private ResultData selectByUserId(@PathVariable String userId){
        return addrService.addrlist(userId);
    }

    //添加地址信息
    @PostMapping
    private ResultData insertAddr(@RequestBody UserAddr addr){
        return addrService.addrinsert(addr);
    }

    //删除地址信息
    @DeleteMapping("{addrId}")
    private ResultData deleteAddr(@PathVariable String addrId){
        return addrService.addrdelete(addrId);
    }

    //修改地址信息
    @PutMapping
    private ResultData updateAddr(@RequestBody UserAddr addr){
        return addrService.addrupdate(addr);
    }

    //修改默认地址
    @PutMapping("moren")
    private ResultData updateAddrCommon(@RequestBody UserAddr addr){
        return addrService.addrMoRen(addr);
    }
}
